home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / BUTTONS / RBUTTON / BPANEL.PAS next >
Pascal/Delphi Source File  |  1996-11-05  |  5KB  |  152 lines

  1. {-------------------------------------------------------------
  2. -BPanel:  Visible Component used to display beveled edges    -
  3. -simular to edges seen between button bars and pull-down     -
  4. -menus in Windows 95.  Any combination of top,bottom,left and-
  5. -right bevels can be shown.                                  -
  6. --------------------------------------------------------------
  7. - !INSTALLATION!:  In Delphi, go to Options|Install Component-
  8. - and Add BPReg.pas.  This will add both components.         -
  9. --------------------------------------------------------------
  10. -Programmed by Brendan Rempel, October 1996                  -
  11. -Copyright 1996; All Rights Reserved                         -
  12. -Send any comments/change requests/etc. to:                  -
  13. -   rempelb@mail.pr-unlimited.com                            -
  14. -                                                            -
  15. -This component is hereby given to the public domain.  I do  -
  16. -claim copyright of this code and I hereby prohibit the sale -
  17. -of the source or compiled code to anyone for any amount.    -
  18. -------------------------------------------------------------}
  19. unit Bpanel;
  20.  
  21. interface
  22.  
  23. uses
  24.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  25.   Forms, Dialogs, ExtCtrls;
  26.  
  27. type
  28.   TBevelType = ( btInset, btOutset );
  29.  
  30. type
  31.   TBevelPanel = class(TCustomPanel)
  32.   private
  33.     { Private declarations }
  34.     FDrawTop:   boolean;
  35.     FDrawBottom:boolean;
  36.     FDrawLeft:  boolean;
  37.     FDrawRight: boolean;
  38.  
  39.     FBevelType: TBevelType;
  40.   protected
  41.     { Protected declarations }
  42.     procedure SetDrawTop(newDrawTop: boolean);
  43.     procedure SetDrawBottom(newDrawBottom: boolean);
  44.     procedure SetDrawLeft(newDrawLeft: boolean);
  45.     procedure SetDrawRight(newDrawRight: boolean);
  46.  
  47.     procedure SetBevelType(newBevelType: TBevelType);
  48.   public
  49.     { Public declarations }
  50.     procedure Paint; override;
  51.     constructor Create(AOwner: TComponent); override;
  52.   published
  53.     { Published declarations }
  54.     property DrawTop:    boolean read FDrawTop    write SetDrawTop;
  55.     property DrawBottom: boolean read FDrawBottom write SetDrawBottom;
  56.     property DrawLeft:   boolean read FDrawLeft   write SetDrawLeft;
  57.     property DrawRight:  boolean read FDrawRight  write SetDrawRight;
  58.  
  59.     property BevelType:  TBevelType read FBevelType write SetBevelType;
  60.  
  61.     property Align;
  62.     property Color;
  63.     property Cursor;
  64.   end;
  65.  
  66. implementation
  67.  
  68. procedure TBevelPanel.SetDrawTop(newDrawTop: boolean);
  69. begin
  70.    FDrawTop:= newDrawTop;
  71.    Invalidate;
  72. end;
  73.  
  74. procedure TBevelPanel.SetDrawBottom(newDrawBottom: boolean);
  75. begin
  76.    FDrawBottom:= newDrawBottom;
  77.    Invalidate;
  78. end;
  79.  
  80. procedure TBevelPanel.SetDrawLeft(newDrawLeft: boolean);
  81. begin
  82.    FDrawLeft:= newDrawLeft;
  83.    Invalidate;
  84. end;
  85.  
  86. procedure TBevelPanel.SetDrawRight(newDrawRight: boolean);
  87. begin
  88.    FDrawRight:= newDrawRight;
  89.    Invalidate;
  90. end;
  91.  
  92. procedure TBevelPanel.SetBevelType(newBevelType: TBevelType);
  93. begin
  94.    FBevelType:= newBevelType;
  95.    Invalidate;
  96. end;
  97.  
  98. constructor TBevelPanel.Create(AOwner: TComponent);
  99. begin
  100.    inherited Create(AOwner);
  101.    Width:= 100;
  102.    Height:= 30;
  103.    FBevelType:= btInset;
  104.    FDrawBottom:= True;
  105.    Color:= clBtnFace;
  106. end;
  107.  
  108. procedure TBevelPanel.Paint;
  109. var
  110.    inColor, outColor: TColor;
  111. begin
  112.    if FBevelType = btInset then          { set bevel colors }
  113.    begin
  114.       inColor:= clBtnShadow;
  115.       outColor:=clBtnHighlight;
  116.    end
  117.    else
  118.    begin
  119.       outColor:=clBtnShadow;
  120.       inColor:= clBtnHighlight;
  121.    end;
  122.  
  123.    with Canvas do
  124.    begin
  125.       pen.color:= clBtnFace; brush.color:= Color;
  126.       Rectangle(0,0,width-1,height-1);   { clear center }
  127.  
  128.       if FDrawBottom then                { draw bottom? }
  129.       begin
  130.          pen.Color:= outColor; MoveTo(0,Height-1); LineTo(Width-1,Height-1);
  131.          pen.Color:= inColor;  MoveTo(0,Height-2); LineTo(Width-1,Height-2);
  132.       end;
  133.       if FDrawRight then
  134.       begin                              { draw right? }
  135.          pen.Color:= outColor; MoveTo(Width-1,0); LineTo(Width-1,Height-1);
  136.          pen.Color:= inColor;  MoveTo(Width-2,0); LineTo(Width-2,Height-1);
  137.       end;
  138.       if FDrawTop then
  139.       begin                              { draw top? }
  140.          pen.Color:= outColor; MoveTo(0,1); LineTo(Width-1,1);
  141.          pen.Color:= inColor;  MoveTo(0,0); LineTo(Width-1,0);
  142.       end;
  143.       if FDrawLeft then
  144.       begin                              { draw left? }
  145.          pen.Color:= outColor; MoveTo(1,0); LineTo(1,Height-1);
  146.          pen.Color:= inColor;  MoveTo(0,0); LineTo(0,Height-1);
  147.       end;
  148.    end;
  149. end;
  150.  
  151. end.
  152.